package com.ruoyi.web.controller.basicInformation;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.system.basicInformation.vo.TAlarmCountVo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.basicInformation.vo.TAlarmVo;
import com.ruoyi.system.basicInformation.bo.TAlarmQueryBo;
import com.ruoyi.system.basicInformation.bo.TAlarmAddBo;
import com.ruoyi.system.basicInformation.bo.TAlarmEditBo;
import com.ruoyi.system.basicInformation.service.ITAlarmService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 报警信息Controller
 * 
 * @author ruoyi
 * @date 2021-05-19
 */
@Api(value = "报警信息控制器", tags = {"报警信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/basicInformation/alarm")
public class TAlarmController extends BaseController {

    private final ITAlarmService iTAlarmService;

    /**
     * 查询报警信息列表
     */
    @ApiOperation("查询报警信息列表")
    @PreAuthorize("@ss.hasPermi('basicInformation:alarm:list')")
    @GetMapping("/list")
    public TableDataInfo<TAlarmVo> list(TAlarmQueryBo bo) {
        startPage();
        List<TAlarmVo> list = iTAlarmService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 查询报警信息列表
     */
    @ApiOperation("查询报警信息列表")
//    @PreAuthorize("@ss.hasPermi('basicInformation:alarm:queryListForMap')")
    @GetMapping("/queryListForMap")
    public TableDataInfo<TAlarmVo> queryListForMap(TAlarmQueryBo bo) {
        startPage();
        List<TAlarmVo> list = iTAlarmService.queryListForMap(bo);
        return getDataTable(list);
    }
    /**
     * 用户报警推送接口
     */
    @ApiOperation("用户报警推送接口")
    @PreAuthorize("@ss.hasPermi('basicInformation:alarm:list')")
    @GetMapping("/listTAlarm")
    public TableDataInfo<TAlarmVo> listTAlarm(TAlarmQueryBo bo) {
        startPage();
        List<TAlarmVo> list = iTAlarmService.listTAlarmVo(bo);
        return getDataTable(list);
    }

    /**
     * 导出报警信息列表
     */
    @ApiOperation("导出报警信息列表")
    @PreAuthorize("@ss.hasPermi('basicInformation:alarm:export')")
    @Log(title = "报警信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TAlarmVo> export(TAlarmQueryBo bo) {
        startPage();
        List<TAlarmVo> list = iTAlarmService.queryListForExcel(bo);
        ExcelUtil<TAlarmVo> util = new ExcelUtil<TAlarmVo>(TAlarmVo.class);
        return util.exportExcel(list, "报警信息");
    }

    /**
     * 获取报警信息详细信息
     */
    @ApiOperation("获取报警信息详细信息")
    @PreAuthorize("@ss.hasPermi('basicInformation:alarm:query')")
    @GetMapping("/{id}")
    public AjaxResult<TAlarmVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iTAlarmService.queryById(id));
    }

    /**
     * 新增报警信息
     */
    @ApiOperation("新增报警信息")
    @PreAuthorize("@ss.hasPermi('basicInformation:alarm:add')")
    @Log(title = "报警信息", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TAlarmAddBo bo) {
        return toAjax(iTAlarmService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改报警信息
     */
    @ApiOperation("修改报警信息")
    @PreAuthorize("@ss.hasPermi('basicInformation:alarm:edit')")
    @Log(title = "修改报警信息", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TAlarmEditBo bo) {
        return toAjax(iTAlarmService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 报警信息审核
     */
    @ApiOperation("审核")
    @PreAuthorize("@ss.hasPermi('basicInformation:alarm:apply')")
    @Log(title = "报警信息审核", businessType = BusinessType.UPDATE)
    @PostMapping("/apply")
    public AjaxResult<Void> apply(@RequestBody TAlarmEditBo bo) {
        return toAjax(iTAlarmService.apply(bo) ? 1 : 0);
    }
    /**
     * 删除报警信息
     */
    @ApiOperation("删除报警信息")
    @PreAuthorize("@ss.hasPermi('basicInformation:alarm:remove')")
    @Log(title = "报警信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iTAlarmService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    /**
     * 查询报警信息当天数据
     */
    @ApiOperation("查询报警信息当天数据")
//    @PreAuthorize("@ss.hasPermi('basicInformation:alarm:toDayCount')")
    @GetMapping("/toDayCount/{isToDay}")
    public AjaxResult<TAlarmCountVo> toDayCount(@PathVariable Integer isToDay) {
        return AjaxResult.success(iTAlarmService.toDayCount(isToDay));
    }
}
